<?php
/**
 * 微信粉丝标签管理
 * User: Administrator
 * Date: 2019/11/27 0027
 * Time: 13:32
 */

namespace app\admin\controller;


use app\admin\traits\controller\WxTags;
use think\Db;
use think\Loader;

class WechatTags extends BasicAdmin{

    use WxTags;

    /**
     * 指定当前数据表
     * @var string
     */
    public $table = 'WechatFansTags';

    //粉丝标签列表
    public function index(){
        if($this->request->isPost()){
            $param = $this->request->param();
            $db = Db::name($this->table)->order('id '.$param['order']);
            foreach (['name'] as $key) {
                (isset($param[$key]) && $param[$key] !== '') && $db->whereLike($key, "%{$param[$key]}%");
            }
            (isset($param['status']) && $param['status'] !== '') && $db->where('status',$param['status']);
            return parent::_list($db,$param);
        }
        $this->title = '微信管理 > 微信粉丝标签管理';
        return $this->fetch('wechat/tags/index', ['title' => $this->title]);
    }

    //添加粉丝标签
    public function add(){
        return $this->_form($this->table, 'wechat/tags/form');
    }

    //编辑粉丝标签
    public function edit(){
        return $this->_form($this->table, 'wechat/tags/form');
    }

    //删除粉丝标签
    public function del(){
        if($this->request->isPost()){
            $data = array_filter($this->request->post());
            $validate = Loader::validate('WxTag');
            if(!$validate->scene('delete')->check($data)){
                $this->result(null,'0',$validate->getError(),'json');
            }else{
                $status = $this->_delete($data);
                $ret = doReturn('粉丝标签删除成功！','粉丝标签删除失败, 请稍候再试!',$status,[],'json');
                $this->resultArr($ret);
            }
        }
    }

    //同步粉丝标签
    public function sync(){
        if($this->request->isPost()){
            $status = $this->_sync();
            $ret = doReturn('同步获取所有粉丝标签成功!','同步获取粉丝标签失败, 请稍候再!试!',$status,[],'json');
            $this->resultArr($ret);
        }
    }

}